package com.gwm.item.client;

import com.gwm.common.vo.PageResult;
import com.gwm.item.dto.*;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@FeignClient(value = "item-service")
public interface ItemClient {


    @GetMapping(value = "/brand/of/category",name = "根据分类id查询品牌信息")
    public List<BrandDTO> findBrandListByCategoryId(@RequestParam("id") Long categoryId);

    @GetMapping(value = "/category/of/parent",name = "根据parentid获取分类信息")
    public List<CategoryDTO> findCategoryListByParentId(@RequestParam("pid") Long pid);

    @GetMapping(value = "/category/of/brand",name = "根据品牌id获取分类信息")
    public List<CategoryDTO> findCategoryListByBrandId(@RequestParam("id") Long brandId);

    /**
     * 分页查询商品
     * @param page
     * @param rows
     * @param saleable
     * @param key
     * @return
     */
    @GetMapping(value = "/spu/page",name = "分页查询spu列表")
    public PageResult<SpuDTO> findSpuPage(
            @RequestParam(value = "page",defaultValue ="1") Integer page,
            @RequestParam(value = "rows",defaultValue = "5") Integer rows,
            @RequestParam(value = "key",required = false) String key,
            @RequestParam(value = "saleable",required = false) Boolean saleable
    );


    /**
     * 根据spuID查询spuDetail
     * @param id spuID
     * @return SpuDetail
     */
    @GetMapping(value = "/spu/detail",name = "根据spuId查询SPUDetail")
    public SpuDetailDTO findSpuDetailBySpuId(@RequestParam("id") Long spuId);


    /**
     * 根据spu的id查询sku
     * @param id
     * @return
     */
    @GetMapping(value = "/sku/of/spu",name = "根据spuId查询sku集合")
    public List<SkuDTO> findSkuListBySpuId(
            @RequestParam("id") Long spuId
    );

    @GetMapping(value = "/spec/groups/of/category",name = "根据分类id获取规格组")
    public List<SpecGroupDTO>  findSpecGroupByCategoryId(@RequestParam("id") Long categoryId);


    @GetMapping(value = "/spec/params",name = "根据分类id或组id获取规格参数")
    public List<SpecParamDTO>  findSpecParamByCategoryIdOrGroupId(
            @RequestParam(value = "cid",required = false) Long categoryId,
            @RequestParam(value = "gid",required = false) Long groupId,
            @RequestParam(value = "searching",required = false) Boolean searching
    );

    @GetMapping(value = "/brand/findBrandListByIds",name = "根据品牌ids获取品牌")
    List<BrandDTO> findBrandListByBrandIdList(@RequestParam("ids") List<Long> ids);

    @GetMapping(value = "/category/findCategoryListByIds",name = "根据分类ids获取分类")
    List<CategoryDTO> findCategoryListByIds(@RequestParam("ids") List<Long> ids);

    @GetMapping(value = "/spu/{id}",name = "根据spuId查询SPU")
    SpuDTO findSpuBySpuId(@PathVariable("id")Long spuId);

    /**
     * 根据id查询品牌
     * @param id
     * @return
     */
    @GetMapping(value = "/brand/{id}",name = "根据品牌id获取品牌")
    BrandDTO findBrandByBrandId(@PathVariable("id") Long brandId);



    @GetMapping(value = "/sku/list",name = "根据skuId集合查询sku集合")
    public List<SkuDTO> findSkuListBySkuIds(
            @RequestParam("ids") List<Long> ids
    );


    @PutMapping("/stock/minus")
    public Void stockMinus(@RequestBody Map<Long, Integer> skuIdAndNumMap);

    @PutMapping("/stock/plus")
    public Void  stockPlus(Map<Long, Integer> skuIdAndNumMap);

    @GetMapping("/time/getNow")
    public String fetchCurrentTime();




}
